home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solon.com (Peter Seebach)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: File Based linked list
- Date: 22 Feb 1996 14:43:36 -0600
- Organization: Usenet Fact Police (Undercover)
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4gikho$jbc@solutions.solon.com>
- References: <Pine.SOL.3.90.960219171637.21117B-100000@eddie>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <Pine.SOL.3.90.960219171637.21117B-100000@eddie>,
- Khan Riaz Ahmad <a228khao@cdf.toronto.edu> wrote:
- > Anyone know how to write a file based linked list... How
- >different is it to implement then a regular memory based linked list??
- >Any source code would be greatly appriciated... BTW I am a student and I
- >need it for an assignment...
-
- This should work:
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct { FILE *f; char *s; } l;
-
- int
- main() {
- char s[80], t[80] = "";
- l l = { 0, 0 };
-
- while (fgets(s, 80, stdin)) {
- strtok(s, "\n");
- if (!strlen(s)) continue;
- if (strcmp(s, "quit") == 0) break;
- if (!*t) strcpy(t, s);
- if (l.f) { l.s = s; fprintf(l.f, "%s\n", l.s); fclose(l.f); }
- l.f = fopen(s, "w");
- if (!l.f) { break; }
- }
- fprintf(l.f, "\n") && fclose(l.f);
- /* print the list out */
- for (l.f = fopen(strcpy(l.s, t), "r"); l.f;
- (l.f = fopen(strtok(fgets(l.s, 80, l.f), "\n"), "r")) &&
- !remove(l.s)) {
- printf("%s\n", l.s);
- }
- printf("%s", l.s);
- return 0;
- }
-
- ---
- not as well tested as I'd like, but I'm in a bit of a hurry because
- I have to be at a meeting in a bit. You should get the idea anyway.
-
- Good luck!
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.txt
-